package com.dwxt.cdms.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dwxt.cdms.entity.Customer;
import com.dwxt.cdms.entity.HealthMessage;
import org.bouncycastle.cms.PasswordRecipientId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Autowired;

public class Test {
	private static Logger log = LoggerFactory.getLogger(Test.class);

	public static void main(String[] args) {
		//签名【类似于公司名字】
		/**
		 * 类似于： 短信的格式
		 * 	【签名（signName）】内容（message）+一些模板内容
		 * 
		 * */
		String signName = "多维协同安博馨短信";
		//#访问键(阿里云平台注册的)
		String accesskey= "LTAI5tK78ioihQ9Ycyn1gJW1";
		//#访问秘钥(阿里云平台注册的)
		String accessSecret = "TYjmTd0NKWNLJS4x2BAzq7xmf4uH9R";
		
		//内容
		String message ="888888";
		//电话号
		String phone = "13330335507";
		//推送的模板在（阿里云中申请的）
		String templateCode = "SMS_225367056";
		try {
			IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accesskey,accessSecret);
			DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");

			IAcsClient client = new DefaultAcsClient(profile);
			
			SendSmsRequest request = new SendSmsRequest(); 
			
			Map<String, String> map =new HashMap<String, String>();
			map.put("name", "zhangsan");//消息
			map.put("status", "gaoya");//消息
			map.put("phone", "024-84578847");//消息

			request.setMethod(MethodType.POST);
			request.setPhoneNumbers(phone);	//接收号码
			request.setSignName(signName);;	//控制台创建的签名名称
			request.setTemplateCode(templateCode);;// 控制台创建的模板CODE
			request.setTemplateParam(JSON.toJSONString(map));// 短信模板中的变量；数字需要转换为字符串；个人用户每个变量长度必须小于15个字符。"
			SendSmsResponse httpResponse = client.getAcsResponse(request);
			if("OK".equals(httpResponse.getCode())){
				System.out.println("success_消息发送成功");
			}else{
				if(log.isErrorEnabled()){
					log.error(httpResponse.getCode()+"  "+httpResponse.getMessage());
				}
				System.out.println("error_消息发送失败");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("error_消息发送失败");
		}
	}
}
